/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.DataRetrieval;

import Utilities.Constants.VirtualResourceType;
import Utilities.Constants.NetworkType;
import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to
 * retrieve network(s) data is sent to the data retrieval service.
 *
 * @author Angel Sanadinov
 */
public class NetworksDataRetrievalRequest extends VBoxResourceRequest
{
    private NetworkType networkType; //the type of the requested network(s)

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     *
     * @see NetworkType#INVALID_TYPE
     */
    public NetworksDataRetrievalRequest()
    {
        super();
        this.networkType = NetworkType.INVALID_TYPE;
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_NETWORKS);
    }

    /**
     * Constructs a data request for a single network, with the specified network id.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the network resides
     * @param networkType the type of the requested network
     * @param networkId
     */
    public NetworksDataRetrievalRequest(int requestorId, int serverId, NetworkType networkType, String networkId)
    {
        super(requestorId, serverId, networkId);
        this.networkType = networkType;
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_NETWORKS);
    }

    /**
     * Constructs a data request for all available networks of the specified type.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the networks reside
     * @param networkType the type of the requested networks
     */
    public NetworksDataRetrievalRequest(int requestorId, int serverId, NetworkType networkType)
    {
        super(requestorId, serverId);
        this.networkType = networkType;
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_NETWORKS);
    }

    /**
     * Constructs a data request for all available networks, limited by the
     * specified owner id.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the networks reside
     * @param ownerId the id of the networks owner
     * @param networkType the type of the requested networks
     */
    public NetworksDataRetrievalRequest(int requestorId, int serverId, int ownerId, NetworkType networkType)
    {
        super(requestorId, serverId, ownerId);
        this.networkType = networkType;
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_NETWORKS);
    }

    /**
     * Retrieves the network type associated with this request.
     *
     * @return the network type
     */
    public NetworkType getNetworkType()
    {
        return networkType;
    }

    /**
     * Sets the network type of the request.
     *
     * @param networkType the network type
     */
    public void setNetworkType(NetworkType networkType)
    {
        this.networkType = networkType;
    }

    /**
     * Retrieves the type of resource that is being requested.
     *
     * @return <code>VirtualResourceType.NETWORK</code>
     */
    @Override
    public VirtualResourceType getResourceType()
    {
        return VirtualResourceType.NETWORK;
    }

    @Override
    public boolean isValid() {
        if(super.isValid() && networkType != null && networkType != NetworkType.INVALID_TYPE)
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (networkId,limit,ownerId,networkType,resourceRequestType)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return NetworksDataRetrievalRequest.class.getSimpleName()
                + ": (" + getResourceId() + "," + getLimit() + "," + getOwnerId()
                + "," + networkType + "," + getResourceRequestType() + ")";
    }
}
